import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/5
 * Time: 14:18
 */
public class Solution {
//    public int minNumberOfFrogs(String croakOfFrogs) {
//        if (croakOfFrogs.charAt(0) != 'c' || croakOfFrogs.charAt(croakOfFrogs.length() - 1) != 'k') return -1;
//        HashMap<Character, Integer> map = new HashMap<>();
//        map.put('c',0);
//        map.put('r',0);
//        map.put('o',0);
//        map.put('a',0);
//        map.put('k',0);
//        for (int i = 0; i < croakOfFrogs.length(); i++) {
//            Character current = croakOfFrogs.charAt(i);
//            if (current.equals('c') && map.get(current) != -1) {
//                if (map.get('k') > 0){
//                    map.put('k', map.get('k') - 1);
//                }
//                map.put(current, map.get(current) + 1);
//            }else if (current.equals('r') && map.get(current) != -1){
//                map.put(current, map.get(current) + 1);
//                map.put('c', map.get('c') - 1);
//            }else if (current.equals('o') && map.get(current) != -1){
//                map.put(current, map.get(current) + 1);
//                map.put('r', map.get('r') - 1);
//            }else if (current.equals('a') && map.get(current) != -1){
//                map.put(current, map.get(current) + 1);
//                map.put('o', map.get('o') - 1);
//            }else if (current.equals('k') && map.get(current) != -1){
//                map.put(current, map.get(current) + 1);
//                map.put('a', map.get('a') - 1);
//            }
//        }
//        if (map.get('c') == 0 && map.get('r') == 0 &&  map.get('o') == 0 && map.get('a') == 0){
//            return map.get('k');
//        }
//        return -1;
//    }
//    public static void main(String[] args) {
//        Solution solution = new Solution();
//        int croak = solution.minNumberOfFrogs("coark");
//        System.out.println(croak);
//    }
    public int minNumberOfFrogs(String croakOfFrogs){
        String string = "croak";
        int length = string.length();
        int[] hash = new int[length];//模拟哈希表
        Map<Character, Integer> map = new HashMap<>();//[x,x对应的下标]
        for (int i = 0; i < length; i++) {
            map.put(string.charAt(i), i);
        }
        for (char cur : croakOfFrogs.toCharArray()) {
            if (map.get(cur) == 0){
                if (hash[length - 1] != 0) hash[length - 1]--;
                hash[0]++;
            }else {
                int index = map.get(cur);
                if (hash[index - 1] == 0) return -1;
                hash[index - 1]--;
                hash[index]++;
            }
        }
        for (int i = 0; i < length - 1; i++) {
            if (hash[i] != 0) return -1;
        }
        return hash[length - 1];
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int croak = solution.minNumberOfFrogs("coark");
        System.out.println(croak);
    }
}